package fr.ece.ing4.project.artifactgroup;

import java.util.HashSet;
import java.util.Set;

public final class SystemManager {

	private static Set<Airport> airports = new HashSet<Airport>();

	public SystemManager() {
		super();
	}
	
	/**
	 * Returns an instance of Airport
	 * @param code airport code must be 3 chars long
	 * @return the new airport
	 * @throws AMSException
	 */
	public static Airport createAirport(String code) throws AMSException{
		if(code.length() != 3)
			throw new IllegalArgumentException("Code must be 3 chars long");
		
		Airport ap =  new Airport(code);
		if(!airports.add(ap)){
			ap = null;
				throw new AMSException("Airport already exists");
		}
		
		
		return ap;
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			Airport cdg = createAirport("CDG");
			//Airport cdg1 = createAirport("CDG");
			System.out.println(airports);
		} catch (AMSException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
